<?php 

class Master_data extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('anggota_model');
		$this->load->model('staff_model');
	}

	public function index()
	{		
		if($this->session->userdata('logged_in_jtk'))
		{
			$session_data = $this->session->userdata('logged_in_jtk');
			$data['username'] = $session_data['username'];
			$data['menu'] = 2;
			$data['login'] = 1;
			$data['anggota_data'] = $this->anggota_model->get_all_data();
			$data['jum_anggota'] = $this->anggota_model->get_jum_data();
			//$this->load->view('header_view', $data);   
			$this->load->view('header_view');			
			$this->load->view('master_data_view', $data);
		}
		else
		{
			//If no session, redirect to login page
			//redirect('home', 'refresh');
			//$data['username'] = "teu login";
			$data['username'] = "";
			$data['menu'] = 0;
			$data['login'] = 0;
			$this->load->view('master_data_view', $data);
		}
	}
	
	function staff()
	{	
		if($this->session->userdata('logged_in_jtk'))
		{
			$session_data = $this->session->userdata('logged_in_jtk');
			$data['title'] = "Data Staff";
			$data['username'] = $session_data['username'];
			$data['menu'] = 2;
			$data['login'] = 1;
			$data['anggota_data'] = $this->staff_model->get_all_data();
			$data['jum_anggota'] = $this->staff_model->get_jum_data();		
			$data['act'] = 'well';
			//$this->load->view('header_view', $data);   
			$this->load->view('header_view');
			$this->load->view('staff_view', $data);
		}
		else
		{
			//If no session, redirect to login page
			//redirect('home', 'refresh');
			//$data['username'] = "teu login";
			$data['username'] = "";
			$data['menu'] = 0;
			$data['login'] = 0;
			$this->load->view('home_view', $data);
		}		
	}
	
	function staff_add()
	{
		//$id = $this->uri->segment(3);
		$data['title'] = "Tambah Staff";
		//$data['main_content'] = 'anggota/form';
		$data['menu'] = 2;
		$data['act'] = 'add';
		$this->load->view('header_view');
		$this->load->view('staff_view', $data);
		//$data['form_act'] = 'update/'.$id;
		//$data['anggota_data'] = $this->staff_model->get_data_by_id($id);
		//$this->load->view('layout/template', $data);
	}
	
	function add_staff(){
		$data = array(
			'nip' => $this->input->post('nip'), 
			'kode_dosen' => $this->input->post('kode_dosen'), 
			'nama' => $this->input->post('nama'), 
			'hp' => $this->input->post('hp'),
			'email' => $this->input->post('email')
		);
		$this->model_staff->tambah($data);
	}
	
	function staff_edit()
	{
		$id = $this->uri->segment(3);
		$data['title'] = "Edit Staff";
		$data['main_content'] = 'anggota/form';
		$data['act'] = 'edit';
		$data['form_act'] = 'update/'.$id;
		$data['anggota_data'] = $this->staff_model->get_data_by_id($id);
		$this->load->view('layout/template', $data);
	}
}

?>